package com.aismy.admin.service.impl;

import com.aismy.admin.entity.ConsultationMessage;
import com.aismy.admin.mapper.ConsultationMessageMapper;
import com.aismy.admin.service.ConsultationMessageService;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class ConsultationMessageServiceImpl extends ServiceImpl<ConsultationMessageMapper, ConsultationMessage> 
        implements ConsultationMessageService {


    @Override
    public Page<ConsultationMessage> getHistoryMessages(Long consultationId, Integer page, Integer size) {
        Page<ConsultationMessage> messagePage = new Page<>(page, size);
        LambdaQueryWrapper<ConsultationMessage> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ConsultationMessage::getConsultationId, consultationId)
                .orderByAsc(ConsultationMessage::getCreatedAt); // 按时间正序排列
        return page(messagePage, wrapper);
    }

    @Override
    public void markAsRead(List<Long> messageIds) {
        // 批量更新消息状态为已读
        lambdaUpdate()
                .set(ConsultationMessage::getIsRead, true)
                .in(ConsultationMessage::getId, messageIds)
                .update();
    }


} 